package application;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import models.Score;

import android.app.Application;

public class Globalstate extends Application {

	private ArrayList<Score> highScoreList = new ArrayList<Score>();

	public ArrayList<Score> getHighscoreList(){
		return highScoreList;
	}

	public void setHighscoreList(ArrayList<Score> newHighscoreList){
		this.highScoreList = newHighscoreList;
	}

	public void addHighscore(Score newHighscore){
		for (Score score : highScoreList) {
			if(score.getUser() == newHighscore.getUser() && score.getScore() == newHighscore.getScore()){
				return;
			}
		}
		highScoreList.add(newHighscore);
		Collections.sort(highScoreList, new Comparator<Score>() {
			public int compare(Score secondScoreEntry, Score firstScoreEntry) {
				int comparison = secondScoreEntry.compareTo(firstScoreEntry);
				if(comparison == 1){
					return 1;
				}
				else{
					return -1;
				}
			}
		});
		if(highScoreList.size()>10){
			highScoreList.remove(10);
		}
	}
}
